 package com.itic.mall.mobile.test;

import java.text.NumberFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.applications.mail.Mail;
import com.itic.appbase.applications.sys.company.persistence.model.Company;
import com.itic.appbase.applications.sys.company.service.CompanyService;
import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.common.constants.IticConst;
import com.itic.appbase.framework.utils.DateHelper;
import com.itic.appbase.framework.utils.EmojiHelper;
import com.itic.appbase.framework.utils.NumberStringHelper;
import com.itic.appbase.framework.utils.RandomStringHelper;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.mall.mobile.base.BaseMobileInterface;
import com.itic.mall.system.banner.persistence.model.BannerExample;
import com.itic.mall.system.banner.service.BannerService;
import com.itic.mall.system.malltoken.persistence.model.MallTokenExample;
import com.itic.mall.system.marketuser.persistence.model.MarketUser;
import com.itic.mall.system.marketuser.persistence.model.MarketUserExample;
import com.itic.mall.system.marketuser.service.MarketUserService;
import com.itic.mall.system.marketuserproduct.persistence.model.MarketUserProduct;
import com.itic.mall.system.marketuserproduct.persistence.model.MarketUserProductExample;
import com.itic.mall.system.marketuserproduct.service.MarketUserProductService;
import com.itic.mall.system.order.persistence.model.Order;
import com.itic.mall.system.order.persistence.model.OrderExample;
import com.itic.mall.system.orderjd.persistence.model.OrderJd;
import com.itic.mall.system.orderjd.persistence.model.OrderJdExample;
import com.itic.mall.system.orderproducts.persistence.model.OrderProducts;
import com.itic.mall.system.orderproducts.persistence.model.OrderProductsExample;
import com.itic.mall.system.premoney.persistence.model.PreMoney;
import com.itic.mall.system.premoney.persistence.model.PreMoneyExample;
import com.itic.mall.system.premoney.persistence.model.PreMoneyExample.Criteria;
import com.itic.mall.system.premoney.service.PreMoneyService;
import com.itic.mall.system.product.persistence.model.Product;
import com.itic.mall.system.product.persistence.model.ProductExample;
import com.itic.mall.system.productfeedback.persistence.model.ProductFeedback;
import com.itic.mall.system.productfeedback.persistence.model.ProductFeedbackExample;
import com.itic.mall.system.productfeedback.service.ProductFeedbackService;
import com.itic.mall.system.productjd.persistence.model.ProductJd;
import com.itic.mall.system.productjd.persistence.model.ProductJdExample;
import com.itic.mall.system.productjd.service.ProductJdService;
import com.itic.mall.system.productproperty.persistence.model.ProductProperty;
import com.itic.mall.system.productproperty.service.ProductPropertyService;
import com.itic.mall.system.productpropertyvalue.persistence.model.ProductPropertyValue;
import com.itic.mall.system.productpropertyvalue.service.ProductPropertyValueService;
import com.itic.mall.system.productsku.persistence.model.ProductSku;
import com.itic.mall.system.productsku.persistence.model.ProductSkuExample;
import com.itic.mall.system.synctgw.persistence.model.SyncTgw;
import com.itic.mall.system.synctgw.persistence.model.SyncTgwExample;
import com.itic.mall.system.user.persistence.model.MallUser;
import com.itic.mall.system.user.persistence.model.MallUserExample;
import com.itic.mall.system.userpre.persistence.model.UserPre;
import com.itic.mall.system.userpre.service.UserPreService;


/**
 * 友惠家商城中心接口类
 * @author 许小宝
 * 2017年07月25日  14时11分
 */
@Controller
@RequestMapping(value="/mobile/test")
public class MallTestInterface
     extends BaseMobileInterface {
   
	@Autowired
	private ProductJdService productJdService;
	
	@Autowired
	private BannerService bannerService;
	
	@Autowired
	private PreMoneyService preMoneyService;
	
	@Autowired
	private MarketUserService marketUserService;
	
	@Autowired
	private UserPreService userPreService;
	
	@Autowired
	private MarketUserProductService marketUserProductService;
	
	@Autowired
    private ProductPropertyService productPropertyService;
	
    @Autowired
    private ProductPropertyValueService productPropertyValueService;
	
    @Autowired
    private ProductFeedbackService productFeedbackService;
    
	@Autowired
	private CompanyService companyService;
	
	@RequestMapping(value="/backComission")
    @ResponseBody
    public Map<String,Object> backComission(HttpServletRequest request,HttpServletResponse response ){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		
    		
			result = SUCCESS;
			errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG;  	
        	
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	//log(e);
        	logException("MallProductInterface", "index", e.toString(),"折扣商城中心商品列表",e);
    		
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
	    
	@RequestMapping(value="/autoConfirm")
    @ResponseBody
    public Map<String,Object> autoConfirm(HttpServletRequest request,HttpServletResponse response ){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		OrderProductsExample example = new OrderProductsExample();
    		com.itic.mall.system.orderproducts.persistence.model.OrderProductsExample.Criteria criteria = example.createCriteria();
    		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    		List<OrderProducts> list = orderProductsService.list(example);
    		if( list.size()>0 ){
    			for( OrderProducts temp: list ){
    				//获得token
    				
    			}
    		}
			result = SUCCESS;
			errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG;  	
        	
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	//log(e);
        	logException("MallProductInterface", "index", e.toString(),"折扣商城中心商品列表",e);
    		
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
	
	
	 @RequestMapping(value="/filterUserNickName")
	    @ResponseBody
	    public Map<String,Object> filterUserNickName(HttpServletRequest request,HttpServletResponse response ){
	    	Map<String, Object> resultMap = new HashMap<String,Object>();
	    	String result = FAIL;
	    	String errorCode = PARAM_ERROR_CODE;
	    	String errorMsg = PARAM_ERROR_MSG;
	    	try{
	    		/*MarketUserExample example2 = new MarketUserExample();
	    		Criteria criteria = example2.createCriteria();
	    		criteria.andIsEffectiveEqualTo(DBConst.TRUE);
	    		
	    		List<MarketUser> list = marketUserService.list(example2);
	    		for( MarketUser temp : list ){
	    			String userNickName = temp.getUserNickName();
	    			userNickName=userNickName.replace("*", "");
	    			userNickName.replace(" ", "");
	    			temp.setUserNickName(userNickName);
	    			marketUserService.edit(temp);
	    		}*/
	    		
	    		MallUserExample example = new MallUserExample();
	    		com.itic.mall.system.user.persistence.model.MallUserExample.Criteria criteria2 = example.createCriteria();
	    		criteria2.andIsEffectiveEqualTo(DBConst.TRUE);
	    		List<MallUser> list2 = mallUserService.list(example);
	    		
	    		for( MallUser tmp: list2 ){
	    			String userNickName = tmp.getUserNickName();
	    			if( null != userNickName ){
	    				userNickName = userNickName.replace("*", "");
		    			userNickName = userNickName.replace(" ", "");
		    			tmp.setUserNickName(userNickName);
		    			mallUserService.edit(tmp);
	    			}
	    		}
	    		
				result = SUCCESS;
				errorCode = SUCCESS_ERROR_CODE;
	        	errorMsg = SUCCESS_ERROR_MSG;  	
	        	
	    	}catch(Exception e){
	    		errorCode = SERVER_ERROR_CODE;
	        	errorMsg = SERVER_ERROR_MSG;
	        	//log(e);
	        	logException("MallProductInterface", "index", e.toString(),"折扣商城中心商品列表",e);
	    		
	    	}
	    	resultMap.put(RESULT, result);
	    	resultMap.put(ERROR_CODE, errorCode);
	    	resultMap.put(ERROR_MSG, errorMsg);
	    	isCrrossDomain(response);
	    	return resultMap;
	    }
	    
	 
    @RequestMapping(value="/randomTotalSales")
    @ResponseBody
    public Map<String,Object> randomTotalSales(HttpServletRequest request,HttpServletResponse response ){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		/*
            ProductExample example = new ProductExample();
            List<Product> list = productService.list(example);
            for( Product temp: list ){
                String randomString = RandomStringHelper.randomNumStr(3);
            	temp.setTotalSales(randomString);
            	productService.edit(temp);
            }*/
    		ProductJdExample example = new ProductJdExample();
    		
    		List<ProductJd> list = productJdService.list(example);
    		for( ProductJd temp: list ){
                String randomString = RandomStringHelper.randomNumStr(4);
            	temp.setReorder(Integer.parseInt(randomString));
            	productJdService.edit(temp);
            }
            
			result = SUCCESS;
			errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG;  	
        	
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	//log(e);
        	logException("MallProductInterface", "index", e.toString(),"折扣商城中心商品列表",e);
    		
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    
    
    /**
     * 
     * @return
     */
    @RequestMapping(value="/index")
    @ResponseBody
    public String index(){
    	return "index";
    }
    
    /**
     * 
     * @return
     */
    @RequestMapping(value="/mail")
    @ResponseBody
    public String mail()throws Exception{
    	Mail mail = new Mail("smtp.163.com", "18401762162@163.com", "Nizuibang521", true);
    	String[] res=new String[1];
    	res[0]="491368175@qq.com";
    	mail.doSendHtmlEmail("test", "test", res , null, null, null);
    	return "index";
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/sqlone")
    @ResponseBody
    public String sqlone(){
    	BannerExample example = new BannerExample();
    	example.createCriteria();
    	bannerService.list(example);
    	return "success";
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/sqlmuti")
    @ResponseBody
    public String sqlmuti(){
    	ProductJdExample example = new ProductJdExample();
    	example.createCriteria();
    	productJdService.list(example);
    	return "success";
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/sqlcount")
    @ResponseBody
    public String sqlcount(){
    	ProductJdExample example = new ProductJdExample();
    	example.createCriteria();
    	productJdService.list(example);
    	return "success";
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/sqlpage")
    @ResponseBody
    public String sqlpage(HttpServletRequest request,HttpServletResponse response){
    	ProductJdExample example = new ProductJdExample();
    	handlePageQueryDefault(request, example);
    	example.createCriteria();
    	productJdService.list(example);
    	return "success";
    }
    
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/back")
    @ResponseBody
    public void back(){
    	PreMoneyExample example = new PreMoneyExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	
    	//25号的预计订单
    	String dateStr = "2017-12-25";
        String startTimeStr = dateStr + IticConst.START_TIME_SUFFIX;
        String endTimeStr = dateStr + IticConst.END_TIME_SUFFIX;
        
    	criteria.andCreateTimeBetween(DateHelper.getDateByStringDate(startTimeStr), DateHelper.getDateByStringDate(endTimeStr));
    	
    	//criteria.andNoteLike("%在京东购买了您分享的商品,预计获得佣金%");
    	
    	List<PreMoney> list = preMoneyService.list(example);
    	
    	for( PreMoney temp: list ){
    		//添加店主的预计收益
    		String marketUserId = temp.getMarketUserId();
    		MarketUser marketUser = marketUserService.get(marketUserId);
    		
    		String preProfit="0";
    		
    		if( StringHelper.isNotBlank(marketUser.getPreProfit())){
    			preProfit = marketUser.getPreProfit();
    		}
    		
    		preProfit = NumberStringHelper.addString(preProfit, temp.getPreMoney());
    		
    		marketUser.setPreProfit(preProfit);
    		
    		marketUserService.edit(marketUser);
    	}
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/backOrderJd")
    @ResponseBody
    public void backOrderJd(){
    	PreMoneyExample example = new PreMoneyExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	
    	//25号的预计订单
    	String dateStr = "2017-12-25";
        String startTimeStr = dateStr + IticConst.START_TIME_SUFFIX;
        String endTimeStr = dateStr + IticConst.END_TIME_SUFFIX;
        
    	criteria.andCreateTimeBetween(DateHelper.getDateByStringDate(startTimeStr), DateHelper.getDateByStringDate(endTimeStr));
    	
    	//criteria.andNoteLike("%在京东购买了您分享的商品,预计获得佣金%");
    	
    	List<PreMoney> list = preMoneyService.list(example);
    	
    	for( PreMoney temp: list ){
    		//添加店主的预计收益
    		String marketUserId = temp.getMarketUserId();
    		MarketUser marketUser = marketUserService.get(marketUserId);
    		
    		String preProfit="0";
    		
    		if( StringHelper.isNotBlank(marketUser.getPreProfit())){
    			preProfit = marketUser.getPreProfit();
    		}
    		
    		preProfit = NumberStringHelper.addString(preProfit, temp.getPreMoney());
    		
    		marketUser.setPreProfit(preProfit);
    		
    		marketUserService.edit(marketUser);
    	}
    }
    
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/setOrderDate")
    @ResponseBody
    public void setOrderDate(){
    	String startDateStr = "2017-12-28 00:00:00";
    	String endDateStr = "2017-12-29 23:59:59";
    	OrderJdExample example = new OrderJdExample();
    	com.itic.mall.system.orderjd.persistence.model.OrderJdExample.Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	
    	criteria.andOrderDateBetween(DateHelper.getDateByStringDate(startDateStr), DateHelper.getDateByStringDate(endDateStr));
    	
    	List<OrderJd> list = orderJdService.list(example);
    	for( OrderJd temp : list ){
    		if( StringHelper.isNotBlank(temp.getOrderNum()) ){
    			PreMoneyExample example2 = new PreMoneyExample();
        		example2.createCriteria().andIsEffectiveEqualTo(DBConst.TRUE).andOrderNumEqualTo(temp.getOrderNum());
        		
        		PreMoney preMoney = new PreMoney();
        		preMoney.setOrderDate(temp.getOrderDate());
        		
        		preMoneyService.editByExample(example2,preMoney);
    		}
    	}
    	
    }
    
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/setOrderDateZy")
    @ResponseBody
    public void setOrderDateZy(){
    	String startDateStr = "2017-11-27 00:00:00";
    	String endDateStr = "2018-1-5 23:59:59";
    	OrderExample example = new OrderExample();
    	com.itic.mall.system.order.persistence.model.OrderExample.Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	
    	criteria.andUpdateTimeBetween(DateHelper.getDateByStringDate(startDateStr), DateHelper.getDateByStringDate(endDateStr));
    	
    	List<Order> list = orderService.list(example);
    	for( Order temp : list ){
    		if( StringHelper.isNotBlank(temp.getOrderNum()) ){
    			PreMoneyExample example2 = new PreMoneyExample();
        		example2.createCriteria().andIsEffectiveEqualTo(DBConst.TRUE).andOrderNumEqualTo(temp.getOrderNum());
        		
        		PreMoney preMoney = new PreMoney();
        		if( StringHelper.isNotBlank(temp.getPayTime()) ){
        			preMoney.setOrderDate( DateHelper.getDateByStringDate(temp.getPayTime()) );
        			preMoneyService.editByExample(example2,preMoney);
        		}
        		
    		}
    	}
    	
    }
    
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/resetPreMoney")
    @ResponseBody
    public void resetPreMoney(){
    	MarketUserExample example = new MarketUserExample();
    	com.itic.mall.system.marketuser.persistence.model.MarketUserExample.Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	List<MarketUser> list = marketUserService.list(example);
    	for( MarketUser temp : list ){
    		String totalPreMoney = preMoneyService.statisTotalPreMoney(temp.getId());
    		if( null != totalPreMoney ){
    			double x = Double.parseDouble(totalPreMoney);
        		NumberFormat ddf1=NumberFormat.getNumberInstance() ;

        		ddf1.setMaximumFractionDigits(2); 
        		String s= ddf1.format(x) ;
        		
        		if( NumberStringHelper.isGreaterNoEqual(s, temp.getPreProfit()) ){
        			UserPre userPre = new UserPre();
        			userPre.setUserId(temp.getId());
        			userPre.setUserName( filterEmoji(temp.getUserNickName()) );
        			userPre.setUserPhone(temp.getUserPhone());
        			userPre.setNowMoney(temp.getPreProfit());
        			userPre.setPreMoney(s);
        			userPreService.add(userPre);
        			
        			temp.setPreProfit(s);
        			marketUserService.edit(temp);
        		}
        		
    		}
    	}
    }
    
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/resetMarketProduct")
    @ResponseBody
    public void resetMarketProduct(){
    	MarketUserProductExample example = new MarketUserProductExample();
    	com.itic.mall.system.marketuserproduct.persistence.model.MarketUserProductExample.Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	List<MarketUserProduct> list = marketUserProductService.list(example);
    	for( MarketUserProduct temp : list ){
    	 	 temp.setTotalSales(Integer.parseInt(RandomStringHelper.randomNumStr(3)));
    		 marketUserProductService.edit(temp);
    	}
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/resetPreMoneyIsCancel")
    @ResponseBody
    public void resetPreMoneyIsCancel(){
    	PreMoneyExample example = new PreMoneyExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	criteria.andIsCancelIsNull();
    	List<PreMoney> list = preMoneyService.list(example);
    	for( PreMoney temp : list ){
    	 	 temp.setIsCancel("0");
    	 	preMoneyService.edit(temp);
    	}
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/deltoken")
    @ResponseBody
    public void deltoken(){
    	MallTokenExample example = new MallTokenExample();
    	com.itic.mall.system.malltoken.persistence.model.MallTokenExample.Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	criteria.andExpiredTimeLessThanOrEqualTo(new Date());
    	mallTokenService.deleteTrueByExample(example);
    	
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/delproductjd")
    @ResponseBody
    public void delproductjd(){
    	ProductJdExample example = new ProductJdExample();
    	com.itic.mall.system.productjd.persistence.model.ProductJdExample.Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.FALSE);
    	productJdService.deleteTrueByExample(example);
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/syncProduct")
    @ResponseBody
    public List<Product> syncProduct(){
    	ProductExample example = new ProductExample();
    	com.itic.mall.system.product.persistence.model.ProductExample.Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	return productService.list(example);
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/syncProductLaiyuan")
    @ResponseBody
    public Company syncProductLaiyuan(String id){
    	return companyService.get(id);
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/syncProductSku")
    @ResponseBody
    public List<ProductSku> syncProductSku( String id ){
    	ProductSkuExample example = new ProductSkuExample();
    	com.itic.mall.system.productsku.persistence.model.ProductSkuExample.Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	criteria.andProductIdEqualTo(id);
    	List<ProductSku> list = productSkuService.list(example);
    	if( list.size()>0 ){
    		for( ProductSku temp : list ){
    			String propertys = temp.getProductPropertys();
    			if( StringHelper.isNotBlank(propertys) ){
    				String[] split = propertys.split(",");
    				String propertysTmp="";
    				for(int i=0;i<split.length;i++){
						String de = split[i];
						String[] split2 = de.split(":");
						if(split2.length>0){
							propertysTmp = getPropertyName(split2[0])+":" ;
    					    if( i==split.length-1 ){
    					    	propertysTmp += getPropertyValueName(split2[1]) ;
    					    }else{
    					    	propertysTmp += getPropertyValueName(split2[1])+"," ;
    					    }
						}
					    
					}
    				temp.setProductPropertys(propertysTmp);
    			}
    			
    		}
    	}
    	return list;
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/syncUsers")
    @ResponseBody
    public List<MallUser> syncUsers( HttpServletRequest request ){
    	MallUserExample example = new MallUserExample();
    	com.itic.mall.system.user.persistence.model.MallUserExample.Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	this.handlePageQueryDefault(request, example);
    	return mallUserService.list(example);
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/syncYuns")
    @ResponseBody
    public List<MarketUser> syncYuns( HttpServletRequest request ){
    	MarketUserExample example = new MarketUserExample();
    	com.itic.mall.system.marketuser.persistence.model.MarketUserExample.Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	this.handlePageQueryDefault(request, example);
    	return marketUserService.list(example);
    }
    
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/syncTgw")
    @ResponseBody
    public List<SyncTgw> syncTgw( HttpServletRequest request, String userId ){
    	SyncTgwExample example = new SyncTgwExample();
    	com.itic.mall.system.synctgw.persistence.model.SyncTgwExample.Criteria criteria = example.createCriteria();
    
    	criteria.andTgwNameLike("%"+userId+"%");
    	
    	List<SyncTgw> list = syncTgwService.list(example);
    	return list;
    	
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/setUserId")
    @ResponseBody
    public List<SyncTgw> setUserId( HttpServletRequest request ){
    	SyncTgwExample example = new SyncTgwExample();
    
    	List<SyncTgw> list = syncTgwService.list(example);
    	if( list.size()>0 ){
    		for( SyncTgw temp : list ){
    			String[] split = temp.getTgwName().split(",");
    		    temp.setUserId(split[0]);
    			syncTgwService.edit(temp);
    		}
    	}
    	return list;
    	
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/delRepeat")
    @ResponseBody
    public String delRepeat( HttpServletRequest request ){
    	
    	return orderJdService.filterRepeat();
    	
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/tgwName")
    @ResponseBody
    public String tgwName( HttpServletRequest request ){
    	
    	SyncTgwExample example = new SyncTgwExample();
    	com.itic.mall.system.synctgw.persistence.model.SyncTgwExample.Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);

    	List<SyncTgw> list = syncTgwService.list(example);
    	for( SyncTgw temp : list ){
    		if( StringHelper.isBlank( temp.getUserNickName() ) ){
    			if( StringHelper.isNotBlank(temp.getUserId())){
    				MarketUser marketUser = marketUserService.get(temp.getUserId());
    				if( null!=marketUser ){
    					temp.setUserNickName( EmojiHelper.filterEmoji(marketUser.getUserNickName()) );
        				syncTgwService.edit(temp);
    				}
    			}
    		}
    	}
    	return "success";
    	
    }
    
    /**
     * sql
     * @return
     */
    @RequestMapping(value="/orderJdName")
    @ResponseBody
    public String orderJdName( HttpServletRequest request ){
    	
    	OrderJdExample example = new OrderJdExample();
    	example.setOrderByClause("CREATE_TIME DESC");
    	
    	com.itic.mall.system.orderjd.persistence.model.OrderJdExample.Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	criteria.andCreateTimeGreaterThanOrEqualTo(DateHelper.getDateByStringDate("2018-01-01 00:00:00"));
    	criteria.andCreateTimeLessThanOrEqualTo(new Date());
    	
    	List<OrderJd> list = orderJdService.list(example);
    	for( OrderJd temp : list ){
    		if( StringHelper.isBlank( temp.getYunUserNickName() ) ){
    			if( StringHelper.isNotBlank(temp.getYunUserId())){
    				MarketUser marketUser = marketUserService.get(temp.getYunUserId());
    				if( null!=marketUser ){
    					temp.setYunUserNickName( EmojiHelper.filterEmoji(marketUser.getUserNickName()) );
        				orderJdService.edit(temp);
    				}
    			}
    			
    			if( StringHelper.isNotBlank(temp.getTgwName())){
    				MarketUser marketUser = marketUserService.get(temp.getTgwName());
    				if( null!=marketUser ){
    					temp.setYunUserNickName( EmojiHelper.filterEmoji(marketUser.getUserNickName()) );
    					temp.setYunUserId(marketUser.getId());
        				orderJdService.edit(temp);
    				}
    			}
    		}
    	}
    	return "success";
    	
    }
    
    
    public String getPropertyName(String id){
    	ProductProperty property = productPropertyService.get(id);
    	return property.getName();
    }
    
    public String getPropertyValueName(String id){
    	ProductPropertyValue propertyValue = productPropertyValueService.get(id);
    	return propertyValue.getPropertyValue();
    }
}